# _*_ coding: UTF-8 _*_
# @Time     : 2022/4/24 10:50
# @Author   : Li Jie
# @Site     : http://www.cdtest.cn/
# @File     : 动作链条操作.py
# @Software : PyCharm

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains


def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get("https://ditu.baidu.com/@11585280.82,3555907.48,12.67z")
    driver.find_element(By.CLASS_NAME, "close-btn").click()  # 关闭登录窗口

    # 点击鼠标右键
    # context_click(element=None):
    # 参数：可以是一个元素，右键点击这个元素
    # 没有参数，默认参数值是None，右键点击鼠标当前位置（打开网页后的鼠标当前位置是坐标原点）
    ActionChains(driver).context_click().perform()
    time.sleep(1)

    # 双击地图
    ActionChains(driver).double_click().perform()
    time.sleep(1)

    # 按住左键不放
    ActionChains(driver).click_and_hold().perform()
    time.sleep(1)

    # 根据距离移动鼠标
    ActionChains(driver).move_by_offset(500, 500).perform()

    # 释放鼠标
    ActionChains(driver).release().perform()
    time.sleep(2)

    # 拖拽鼠标
    # 参数：1.element如果点击当前鼠标位置，传值为None
    # 2.xoffset：x轴移动距离
    # 3.yoffset：y轴移动距离
    ActionChains(driver).drag_and_drop_by_offset(None, -500, -500).perform()
    time.sleep(2)

    # ActionChains可以将多个操作构建成动作的链条依次执行
    ActionChains(driver).click_and_hold().pause(1).move_by_offset(700, 700).pause(1).release().perform()
    time.sleep(5)

    driver.quit()


if __name__ == "__main__":
    foo1()
